


clear all
set more off
set matsize 11000

capture confirm file "Appendix_Results/"
if _rc mkdir "Appendix_Results/"


capture confirm file "Appendix_Results/gphs/"
if _rc mkdir "Appendix_Results/gphs/"





local region  Euro  

local response R_real



use "Data/Big_Pandemics.dta", clear
gen pandemic=1



drop year
ren endyear year
sort year
merge 1:1 year using "Data/RealRateSince1310.dta"
sort year
replace pandemic=0 if pandemic==.
gen pandemic100k=cond(dead>=100000,pandemic,0)
cap drop Horizon
gen Horizon = _n-1 if _n<=41
merge 1:1 year using "Data/sdeaths.dta" , nogen
replace sdeaths =0 if sdeaths==.
replace sdeaths= cond(sdeaths>20000,1,0)
sort year

// generate dummies for various experimnets in Fig A2
gen pandemic_noBD = pandemic100k
gen pandemic_no1920= pandemic100k
gen pandemic_noAsia= pandemic100k
gen pandemic_nowars = pandemic100k

replace pandemic_noBD = 0 if year==1353
replace pandemic_no1920=0 if year==1920 
replace pandemic_noAsia=0 if year>1920 
replace pandemic_nowars= 0 if sdeaths==1

cap drop Horizon
gen Horizon = _n-1 if _n<=41
tsset year


cap drop b0* se0* 
cap drop h0* l0* h1* l1*
tsset year
foreach x of local region {
	foreach y of local response {
	
	gen b0_`x'`y'=0 if Horizon==0
	gen se0_`x'`y'=0 if Horizon==0	
	gen h0_`x'`y'=0 if Horizon==0
	gen l0_`x'`y'=0 if Horizon==0
	gen h1_`x'`y'=0 if Horizon==0
	gen l1_`x'`y'=0 if Horizon==0
	
cap drop raw
gen raw = .
replace raw = `x'`y'


/********** State space specification starts here *************/

constraint 1	[rstar]L.rstar		= 1		/* Random Walk */	
constraint 2	[raw]rstar			= 1		/* Definitional */


cap drop zero								/* generate zero line for figures */
gen zero = 0

tsset year
cap drop r_star

/************	 State space equations	 ******************/

sspace		(rstar L.rstar, state noconstant)		/// /* r-star */
			(raw rstar, noconstant ),				/// /* raw */
			covstate(identity) constraints(1/2) difficult /*method(kdiffuse)*/ iterate(25)
			
			qui{
			/* Generate smoothed estimates of r-star */
			predict r_star if e(sample), states smethod(smooth) equation(rstar)
			
		
		
		
			cap drop `x'`y'`trend
			gen	`x'`y'trend = r_star
			}

			
		

								}
								
						}



// Fig A2. a) no Black Death				
						
foreach y of local response {
	foreach x of local region {
	eststo clear
		forv h=0/40 {
		
						cap drop  d`y'`h'
						gen d`y'`h' = f`h'.`x'`y'trend- l.`x'`y'trend
						reg d`y'`h'  l(0/10).pandemic_noBD  l(2/11).`x'`y'trend  
												
						eststo
						replace b0_`x'`y'  = _b[pandemic_noBD]                      if Horizon==`h'
						replace se0_`x'`y' = _se[pandemic_noBD]                     if Horizon==`h'
						replace h0_`x'`y'  = _b[pandemic_noBD]+2*_se[pandemic_noBD]  if Horizon==`h'
						replace l0_`x'`y'  = _b[pandemic_noBD]-2*_se[pandemic_noBD]  if Horizon==`h'
						replace h1_`x'`y'  = _b[pandemic_noBD]+1*_se[pandemic_noBD]  if Horizon==`h'
						replace l1_`x'`y'  = _b[pandemic_noBD]-1*_se[pandemic_noBD]  if Horizon==`h'
						
						
					
						}
						
		esttab , keep(pandemic*)
		cap drop Zero
		gen Zero=0
		twoway ///
		(  rarea h0_`x'`y' l0_`x'`y' Horizon if Horizon~=. , fc(blue)  fi(10) lcolor(white)  lpattern(none)  )  ///
		(  rarea h1_`x'`y' l1_`x'`y' Horizon if Horizon~=. , fc(blue)  fi(20) lcolor(white) lw(none)  lpattern(none)  )  ///
		(  line  Zero    Horizon if Horizon~=. , lc(gray)  lw(med) lp(dash)                     )  ///		
		(  line  b0_`x'`y'     Horizon if Horizon~=. , lc(blue)  lw(thick) lp(solid)  ///
				xlab(0(10)40, labsize(large)) ylab(-3(1)1, angle(0) labsize(large)  nogrid) xtitle("Years since pandemic event ended",size(large)) ///
				ytitle("Percent",size(large)) ///
				legend( off ) )  ///
		, title()    ///
		xsize(5) ysize(4) scale(1.1) ysc(r(-3 1))  scheme(s1color) graphregion(color(white)) plotregion(color(white)) ///
		name(`x'`y'_bd,replace) /// nodraw
	
		graph save   Appendix_Results/gphs/FigureA2a.gph, replace
		graph export Appendix_Results/FigureA2a.pdf, replace

}
}



// Fig A2. b) no 1920 

cap drop b0* se0* 
cap drop h0* l0* h1* l1*
tsset year
foreach x of local region {
	foreach y of local response {
	gen b0_`x'`y'=0 if Horizon==0
	gen se0_`x'`y'=0 if Horizon==0	
	gen h0_`x'`y'=0 if Horizon==0
	gen l0_`x'`y'=0 if Horizon==0
	gen h1_`x'`y'=0 if Horizon==0
	gen l1_`x'`y'=0 if Horizon==0
	}
	}
	
foreach y of local response {
	foreach x of local region {
	eststo clear
		forv h=1/40 {
		
						cap drop  d`y'`h'
						gen d`y'`h' = f`h'.`x'`y'trend- l.`x'`y'trend
						reg d`y'`h'  l(0/10).pandemic_no1920  l(2/11).`x'`y'trend  
												
						eststo
						replace b0_`x'`y'  = _b[pandemic_no1920]                      if Horizon==`h'
						replace se0_`x'`y' = _se[pandemic_no1920]                     if Horizon==`h'
						replace h0_`x'`y'  = _b[pandemic_no1920]+2*_se[pandemic_no1920]  if Horizon==`h'
						replace l0_`x'`y'  = _b[pandemic_no1920]-2*_se[pandemic_no1920]  if Horizon==`h'
						replace h1_`x'`y'  = _b[pandemic_no1920]+1*_se[pandemic_no1920]  if Horizon==`h'
						replace l1_`x'`y'  = _b[pandemic_no1920]-1*_se[pandemic_no1920]  if Horizon==`h'
						}
						
		esttab , keep(pandemic*)
		cap drop Zero
		gen Zero=0
		twoway ///
		(  rarea h0_`x'`y' l0_`x'`y' Horizon if Horizon~=. , fc(blue)  fi(10) lcolor(white)  lpattern(none)  )  ///
		(  rarea h1_`x'`y' l1_`x'`y' Horizon if Horizon~=. , fc(blue)  fi(20) lcolor(white) lw(none)  lpattern(none)  )  ///
		(  line  Zero    Horizon if Horizon~=. , lc(gray)  lw(med) lp(dash)                     )  ///		
		(  line  b0_`x'`y'     Horizon if Horizon~=. , lc(blue)  lw(thick) lp(solid)  ///
				xlab(0(10)40, labsize(large)) ylab(-3(1)1, angle(0) labsize(large)  nogrid) xtitle("Years since pandemic event ended", size(large)) ///
				ytitle("Percent",size(large)) ///
				legend( off ) )  ///
		, title()    ///
		xsize(5) ysize(4) scale(1.1) ysc(r(-3 1))  scheme(s1color) graphregion(color(white)) plotregion(color(white)) ///
		name(`x'`y'_1920,replace) /// nodraw
	
		graph save   Appendix_Results/gphs/FigureA2b.gph, replace
		graph export Appendix_Results/FigureA2b.pdf, replace

}
}




// Fig A2. c) no post 1920 pandemic event

cap drop b0* se0* 
cap drop h0* l0* h1* l1*
tsset year
foreach x of local region {
	foreach y of local response {
	gen b0_`x'`y'=0 if Horizon==0
	gen se0_`x'`y'=0 if Horizon==0	
	gen h0_`x'`y'=0 if Horizon==0
	gen l0_`x'`y'=0 if Horizon==0
	gen h1_`x'`y'=0 if Horizon==0
	gen l1_`x'`y'=0 if Horizon==0
	}
	}
	
foreach y of local response {
	foreach x of local region {
	eststo clear
		forv h=1/40 {
		
						cap drop  d`y'`h'
						gen d`y'`h' = f`h'.`x'`y'trend- l.`x'`y'trend
						reg d`y'`h'  l(0/10).pandemic_noAsia  l(2/11).`x'`y'trend  
												
						eststo
						replace b0_`x'`y'  = _b[pandemic_noAsia]                      if Horizon==`h'
						replace se0_`x'`y' = _se[pandemic_noAsia]                     if Horizon==`h'
						replace h0_`x'`y'  = _b[pandemic_noAsia]+2*_se[pandemic_noAsia]  if Horizon==`h'
						replace l0_`x'`y'  = _b[pandemic_noAsia]-2*_se[pandemic_noAsia]  if Horizon==`h'
						replace h1_`x'`y'  = _b[pandemic_noAsia]+1*_se[pandemic_noAsia]  if Horizon==`h'
						replace l1_`x'`y'  = _b[pandemic_noAsia]-1*_se[pandemic_noAsia]  if Horizon==`h'
						}
						
		esttab , keep(pandemic*)
		cap drop Zero
		gen Zero=0
		twoway ///
		(  rarea h0_`x'`y' l0_`x'`y' Horizon if Horizon~=. , fc(blue)  fi(10) lcolor(white)  lpattern(none)  )  ///
		(  rarea h1_`x'`y' l1_`x'`y' Horizon if Horizon~=. , fc(blue)  fi(20) lcolor(white) lw(none)  lpattern(none)  )  ///
		(  line  Zero    Horizon if Horizon~=. , lc(gray)  lw(med) lp(dash)                     )  ///		
		(  line  b0_`x'`y'     Horizon if Horizon~=. , lc(blue)  lw(thick) lp(solid)  ///
				xlab(0(10)40, labsize(large)) ylab(-3(1)1, angle(0) labsize(large)  nogrid) xtitle("Years since pandemic event ended", size(large)) ///
				ytitle("Percent",size(large)) ///
				legend( off ) )  ///
		, title()    ///
		xsize(5) ysize(4) scale(1.1) ysc(r(-3 1))  scheme(s1color) graphregion(color(white)) plotregion(color(white)) ///
		name(`x'`y'_Asia,replace) /// nodraw
	
		graph save   Appendix_Results/gphs/FigureA2c.gph, replace
		graph export Appendix_Results/FigureA2c.pdf, replace

}
}


// Fig A2. d) no pandemics coincident with wars

cap drop b0* se0* 
cap drop h0* l0* h1* l1*
tsset year
foreach x of local region {
	foreach y of local response {
	gen b0_`x'`y'=0 if Horizon==0
	gen se0_`x'`y'=0 if Horizon==0	
	gen h0_`x'`y'=0 if Horizon==0
	gen l0_`x'`y'=0 if Horizon==0
	gen h1_`x'`y'=0 if Horizon==0
	gen l1_`x'`y'=0 if Horizon==0
	}
	}
	
foreach y of local response {
	foreach x of local region {
	eststo clear
		forv h=1/40 {
		
						cap drop  d`y'`h'
						gen d`y'`h' = f`h'.`x'`y'trend- l.`x'`y'trend
						reg d`y'`h'  l(0/10).pandemic_nowars  l(2/11).`x'`y'trend  
												
						eststo
						replace b0_`x'`y'  = _b[pandemic_nowars]                      if Horizon==`h'
						replace se0_`x'`y' = _se[pandemic_nowars]                     if Horizon==`h'
						replace h0_`x'`y'  = _b[pandemic_nowars]+2*_se[pandemic_nowars]  if Horizon==`h'
						replace l0_`x'`y'  = _b[pandemic_nowars]-2*_se[pandemic_nowars]  if Horizon==`h'
						replace h1_`x'`y'  = _b[pandemic_nowars]+1*_se[pandemic_nowars]  if Horizon==`h'
						replace l1_`x'`y'  = _b[pandemic_nowars]-1*_se[pandemic_nowars]  if Horizon==`h'
						}
						
		esttab , keep(pandemic*)
		cap drop Zero
		gen Zero=0
		twoway ///
		(  rarea h0_`x'`y' l0_`x'`y' Horizon if Horizon~=. , fc(blue)  fi(10) lcolor(white)  lpattern(none)  )  ///
		(  rarea h1_`x'`y' l1_`x'`y' Horizon if Horizon~=. , fc(blue)  fi(20) lcolor(white) lw(none)  lpattern(none)  )  ///
		(  line  Zero    Horizon if Horizon~=. , lc(gray)  lw(med) lp(dash)                     )  ///		
		(  line  b0_`x'`y'     Horizon if Horizon~=. , lc(blue)  lw(thick) lp(solid)  ///
				xlab(0(10)40, labsize(large)) ylab(-3(1)1, angle(0) labsize(large)  nogrid) xtitle("Years since pandemic event ended", size(large)) ///
				ytitle("Percent",size(large)) ///
				legend( off ) )  ///
		, title()    ///
		xsize(5) ysize(4) scale(1.1) ysc(r(-3 1))  scheme(s1color)  graphregion(color(white)) plotregion(color(white)) ///
		name(`x'`y'_wars,replace) /// nodraw
	
		graph save   Appendix_Results/gphs/FigureA2d.gph, replace
		graph export Appendix_Results/FigureA2d.pdf, replace

}
}

